package com.ruoyi.teach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teach.domain.SchSys;
import com.ruoyi.teach.service.ISchSysService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学制Controller
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@RestController
@RequestMapping("/teach/sys")
public class SchSysController extends BaseController
{
    @Autowired
    private ISchSysService schSysService;

    /**
     * 查询学制列表
     */
    @PreAuthorize("@ss.hasPermi('teach:sys:list')")
    @GetMapping("/list")
    public TableDataInfo list(SchSys schSys)
    {
        startPage();
        List<SchSys> list = schSysService.selectSchSysList(schSys);
        return getDataTable(list);
    }

    /**
     * 导出学制列表
     */
    @PreAuthorize("@ss.hasPermi('teach:sys:export')")
    @Log(title = "学制", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchSys schSys)
    {
        List<SchSys> list = schSysService.selectSchSysList(schSys);
        ExcelUtil<SchSys> util = new ExcelUtil<SchSys>(SchSys.class);
        util.exportExcel(response, list, "学制数据");
    }

    /**
     * 获取学制详细信息
     */
    @PreAuthorize("@ss.hasPermi('teach:sys:query')")
    @GetMapping(value = "/{sId}")
    public AjaxResult getInfo(@PathVariable("sId") Long sId)
    {
        return AjaxResult.success(schSysService.selectSchSysBySId(sId));
    }

    /**
     * 新增学制
     */
    @PreAuthorize("@ss.hasPermi('teach:sys:add')")
    @Log(title = "学制", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SchSys schSys)
    {
        return toAjax(schSysService.insertSchSys(schSys));
    }

    /**
     * 修改学制
     */
    @PreAuthorize("@ss.hasPermi('teach:sys:edit')")
    @Log(title = "学制", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SchSys schSys)
    {
        return toAjax(schSysService.updateSchSys(schSys));
    }

    /**
     * 删除学制
     */
    @PreAuthorize("@ss.hasPermi('teach:sys:remove')")
    @Log(title = "学制", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sIds}")
    public AjaxResult remove(@PathVariable Long[] sIds)
    {
        return toAjax(schSysService.deleteSchSysBySIds(sIds));
    }
}
